package com.mofang.model;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Base64;

import com.mofang.dao.remote.UserRemoteDao;
import com.mofang.utils.MoFangSession;
import com.pactera.framework.exception.DBException;
import com.pactera.framework.exception.NetworkException;
import com.pactera.framework.exception.ServerException;
import com.pactera.framework.exception.TimeoutException;
import com.pactera.framework.http.HttpResult;
import com.pactera.framework.util.Loger;

public class UserModel extends MoFangBaseModel {

	public static final String REP_MANAGER = "1";
	public static final int REP_ID = 1;
	public static final int REP_ASGN_ROLE_ID = 2;
	public static final int REP_ASGN_ROLE_NM = 3;
	public static final int REP_NM = 4;
	public static final int REP_TEL = 5;
	public static final int REP_EMAIL = 6;
	public static final int REP_GVRNMT_ID = 7;
	public static final int Store_ID = 8;
	public static final int CREATER_REP_ID = 9;

	public boolean loginFromRemote(String userName, String password)
			throws TimeoutException, ServerException, NetworkException {

		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		// UserRemoteDao storeRemoteDao = new UserRemoteDao();
		// String signPassword = Base64.encodeToString(password.getBytes(),
		// Base64.DEFAULT);
		// HttpResult httpResult = storeRemoteDao.login(userName, signPassword
		// );
		// String response = preParseHttpResult(httpResult);
		// Loger.d(response);
		// try {
		// JSONObject data = preParseResponse(response);
		// JSONObject securityJson = data.getJSONObject("data");
		// MoFangSession.setJsessionId(securityJson.getString("sessionId"));
		// if (!MoFangSession.getAccount().equals(userName)) {
		// MoFangSession.setIrepStatus(false);
		// MoFangSession.setAccount(userName);
		// }
		// MoFangSession.setName(securityJson.getString("rep_nm"));
		// MoFangSession.setRoleName(securityJson
		// .getString("rep_asgn_role_nm"));
		// MoFangSession.setRoleId(securityJson.getString("rep_asgn_role_id"));
		// MoFangSession.setTelephone(securityJson.getString("rep_tel"));
		// MoFangSession.setEmail(securityJson.getString("rep_email"));
		// MoFangSession.setPassword(password);
		// MoFangSession.setRepID((securityJson.getString("rep_id")));
		// return true;
		// } catch (JSONException e) {
		// Loger.d(e.getMessage());
		// e.printStackTrace();
		// }

		return true;
	}

	/**
	 * logout
	 * 
	 * @throws TimeoutException
	 * @throws NetworkException
	 * @throws DBException
	 * @return
	 */
	public boolean logout() throws DBException, NetworkException {

		// StoreRemoteDao storeRemoteDao=new StoreRemoteDao();
		// HttpResult httpResult = storeRemoteDao.logout();
		// String response = preParseHttpResult(httpResult);
		// Loger.d(response);
		MoFangSession.clearForLogout();

		return true;
	}

	public Boolean sendVerificationCode(String phoneNo)
			throws TimeoutException, ServerException, NetworkException {
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return true;
	}

	public Boolean findPassword(String phoneNo, String newPassword,
			String verificationCode) throws TimeoutException, ServerException,
			NetworkException {
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return true;
	}

	public Boolean userRegister(String register_invitationCode,
			String register_realName, String register_phone,
			String register_captcha, String register_password)
			throws TimeoutException, ServerException, NetworkException {
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return true;
	}

	public Boolean changeUserName(String phone, String newName)
			throws TimeoutException, ServerException, NetworkException {
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return true;
	}

	public Boolean changeUserPassword(String phoneNo, String newPassword,
			String verificationCode) throws TimeoutException, ServerException,
			NetworkException {
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return true;
	}
}
